//
//  CNProfileEditor.swift
//  SwiftUi
//
//  Created by xm on 03/09/2025.
//

import SwiftUI

struct CNProfileEditor: View {
    
    @Binding var profile: User

    
    var body: some View {
        
        withUnsafePointer(to: profile) { pointer in
            print("[CNProfileEditor] profile", pointer)
        }
        
        return  List{
            HStack{
                Text("昵称")
                Divider()
                TextField("昵称", text: $profile.username)
            }
            
            Toggle(isOn: $profile.prefersNotifications) {
                Text("允许通知")
            }
            VStack(alignment: .leading){
                Text("喜欢的季节").bold()
                Picker("喜欢的季节",selection: $profile.prefersSeason){
                    ForEach(User.Season.allCases, id: \.self){ season in
                        Text(season.rawValue).tag(season)
                    }
                }
                .pickerStyle(SegmentedPickerStyle())
            }
            VStack(alignment: .leading) {
//                        Text("生日").bold()
                DatePicker(
                    "生日",
                    selection: $profile.birthday,
                    displayedComponents: .date)
            }
            
        }.listStyle(.plain)
    }
}

#Preview {
    CNProfileEditor(profile: .constant(.default))
}
